using System;
using System.Web.UI;
public static class StateBagExtensions
{
	public static T Get<T>(this StateBag state, string key)
	{
		return state.Get(key, default(T));
	}
	public static T Get<T>(this StateBag state, string key, T defaultValue)
	{
		object obj = state[key];
		return (T)(obj ?? defaultValue);
	}
	public static T Ensure<T>(this StateBag state, string key) where T : class, new()
	{
		T t = state.Get<T>(key);
		if (t == null)
		{
			t = Activator.CreateInstance<T>();
			state.Set(key, t);
		}
		return t;
	}
	public static void Set(this StateBag state, string key, object value)
	{
		state[key] = value;
	}
}
